/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.bean;

import com.aal.entity.Product;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author quy
 */
@Stateless
public class ProductFacade extends AbstractFacade<Product> implements ProductFacadeLocal {
    @PersistenceContext(unitName = "AAL-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public ProductFacade() {
        super(Product.class);
    }
    public List<Product> findProduct(String productName) {
        Query query = em.createNamedQuery("Product.findByProductName");
              query.setParameter("productName",'%'+productName+'%');
        return query.getResultList();
    }
    public Product findName(String productName){
        Query query = em.createNamedQuery("Product.findName");
            query.setParameter("productName", productName);
        return (Product) query.getSingleResult();
    }
}
